package com.email.util;

import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import java.util.Date;
import java.util.Properties;

/**
 * Author：hanll
 * ClassName：EmailTest
 * Date：2022/10/3 17:38
 * Version：1.0
 * Description：发送邮箱
 */
public class EmailTest {
    public static void main(String[] args) throws MessagingException {
        Properties prop = new Properties();
        prop.put("mail.transport.protocol", "smtp");
        prop.put("mail.smtp.host", "smtp.qq.com");
        Session session = Session.getInstance(prop);
        MimeMessage message = new MimeMessage(session);
        message.setFrom(new InternetAddress("2896850293@qq.com"));
        message.setSentDate(new Date());
        //1551455480@qq.com
        message.setRecipient(MimeMessage.RecipientType.TO, new InternetAddress("1551455480@qq.com"));
        message.setSubject("呆头的测试邮件");
        message.setText("啵啵啵!!!");
        message.saveChanges();
        Transport transport = session.getTransport();
        //邮箱认证
        transport.connect("2896850293@qq.com", "uaftmagienkadfac");
        transport.sendMessage(message, message.getAllRecipients());
        System.out.println("发送成功！！！");
        transport.close();
    }
}
